home *** CD-ROM | disk | FTP | other *** search
- /*
- File: "MPDelayUntilTest.c"
-
- Description: This is a application to test/demo the MT/MP MPDelayUntil API.
-
- Version: v0.0
-
- File Ownership:
-
- Technology: MultiTasking/MultiProcessing
-
- Copyright: © Copyright 2000 Apple Computer, Inc. All rights reserved.
-
- Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
- ("Apple") in consideration of your agreement to the following terms, and your
- use, installation, modification or redistribution of this Apple software
- constitutes acceptance of these terms. If you do not agree with these terms,
- please do not use, install, modify or redistribute this Apple software.
-
- In consideration of your agreement to abide by the following terms, and subject
- to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
- copyrights in this original Apple software (the "Apple Software"), to use,
- reproduce, modify and redistribute the Apple Software, with or without
- modifications, in source and/or binary forms; provided that if you redistribute
- the Apple Software in its entirety and without modifications, you must retain
- this notice and the following text and disclaimers in all such redistributions of
- the Apple Software. Neither the name, trademarks, service marks or logos of
- Apple Computer, Inc. may be used to endorse or promote products derived from the
- Apple Software without specific prior written permission from Apple. Except as
- expressly stated in this notice, no other rights or licenses, express or implied,
- are granted by Apple herein, including but not limited to any patent rights that
- may be infringed by your derivative works or by other works in which the Apple
- Software may be incorporated.
-
- The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
- WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
- WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
- COMBINATION WITH YOUR PRODUCTS.
-
- IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
- OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
- (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
- Author Initials:
-
- gaw
-
- */
-
- #pragma mark #Includes
- #include <MacTypes.h>
- #include <Fonts.h>
- #include <Multiprocessing.h>
-
- #include <stdio.h> // for printf & fflush
- #include <SIOUX.h> // for SIOUXSettings stuff
- #include <SIOUXGlobals.h> // for SIOUXQuitting
-
- #pragma mark typedefs, structs, enums, defines, etc.
- typedef struct MyTaskParam_Struct
- {
- Duration fDuration;
- OSStatus fOSStatus;
- Boolean* fFlagPtr;
- } MyTaskParam_Rec,*MyTaskParam_Ptr,**MyTaskParam_Hdl;
-
- #pragma mark static (local) functions
- // This is our MP task
- static OSStatus MyTask(void *parameter)
- {
- // convert our (void*) parameter into a pointer to our task parameter record
- MyTaskParam_Ptr tMyTaskParam_Ptr = (MyTaskParam_Ptr) parameter;
- AbsoluteTime expirationTime;
-
- // calculate the expiration time based on the current
- // absolute time plus a duration and arm the timer.
- expirationTime = UpTime();
- expirationTime = AddDurationToAbsolute(tMyTaskParam_Ptr->fDuration,expirationTime);
-
- // Ok, Delay until our expiration time.
- tMyTaskParam_Ptr->fOSStatus = MPDelayUntil(&expirationTime);
-
- // set our done flag
- *tMyTaskParam_Ptr->fFlagPtr = true;
-
- // and return our status.
- return (tMyTaskParam_Ptr->fOSStatus);
- }
-
- #pragma mark exported functions
- void main(void)
- {
- MyTaskParam_Rec tMyTaskParam_Rec;
- OSStatus anErr;
- MPTaskID tMyMPTaskID;
- UInt32 i, num;
- volatile Boolean done = false;
- char buff[10];
-
- // Set the SIOUX window defaults
- SIOUXSettings.autocloseonquit = false;
- SIOUXSettings.asktosaveonclose = false;
- SIOUXSettings.showstatusline = false;
- SIOUXSettings.columns = 132;
- SIOUXSettings.rows = 24;
- SIOUXSettings.fontsize = 10;
- GetFNum("\pMonaco",&SIOUXSettings.fontid);
- SIOUXSettings.standalone = true;
-
- printf("MPDelayUntilTest starting!\n");
-
- // Make sure that the MP library is loaded
- if (!MPLibraryIsLoaded())
- {
- printf("The MP library did not load.\n");
- return;
- }
-
- { // for giggles we'll dump out the MP Library version info
- Ptr tVersionCStringPtr;
- UInt32 major,minor,release,revision;
-
- _MPLibraryVersion(&tVersionCStringPtr,&major,&minor,&release,&revision);
-
- printf("\n Version: \"%s\", major: %ld, minor: %ld, release: %ld, revision: %ld.\n",tVersionCStringPtr,major,minor,release,revision);
- }
-
- // setup our task parameters
- tMyTaskParam_Rec.fDuration = 10 * durationSecond;
- tMyTaskParam_Rec.fOSStatus = noErr;
- tMyTaskParam_Rec.fFlagPtr = (Boolean*) &done;
-
- // create our task
- anErr = MPCreateTask(MyTask, (void *) &tMyTaskParam_Rec,0,NULL,0,0,kNilOptions,&tMyMPTaskID);
- if (noErr != anErr)
- printf(" MPCreateTask: %d.\n", anErr);
- else
- printf("Waiting 10 seconds...\n");
-
- // it's importaint that our WaitNextEvent loop not be CPU bound
- // so we use a sleep time of one with WNE.
- while (!done && (noErr == anErr) && !SIOUXQuitting)
- {
- EventRecord theEvent;
-
- WaitNextEvent(everyEvent,&theEvent,1,nil);
- SIOUXHandleOneEvent(&theEvent); // tell SIOUX to handle the event
- }
-
- // if our task had an error then report it
- if (noErr != tMyTaskParam_Rec.fOSStatus)
- printf("MyTask error: %d.",tMyTaskParam_Rec.fOSStatus);
-
- if (noErr == anErr)
- printf("Done!\n");
-
- printf("Press command-Q to quit.");
- }
-